<script>

window.fbAsyncInit = function() {
	FB.init({
	  appId      : '<?php echo Zend_Registry::get('facebook')->app_id ?>',
	  cookie     : false,  // enable cookies to allow the server to access 
	                      // the session
	  xfbml      : true,  // parse social plugins on this page
	  version    : 'v2.1' // use version 2.1
	});
};

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

  function statusChangeCallback(response) {

    if (response.status === 'connected') {
        FB.api('/me', function(response) {
            if (response.id){
	            $.getJSON('<?php echo $this->baseUrl()?>'+'/usuario/ajax-atualizar-link-facebook/id_facebook/' + response.id,
	                    function(j){
							if (j == 'ok'){
								  window.location= '<?php echo $this->baseUrl() ?>' + '/usuario/board/message/' + '<?php echo Messages::FACEBOOK_LINK_ATUALIZADO ?>';
							}
	            });	
        	}	
		});
    } else if (response.status === 'not_authorized') {
    } else {
    }
  }

	function checkLoginState() {
		FB.logout(function(response) {});
		  
		FB.getLoginStatus(function(response) {
	      		statusChangeCallback(response);
	    });
	}  
</script>

<div class="container-fluid">
    <div class="row">
        <div class="page-header">
            <h1>Vincular <small>esta conta ao Facebook</small></h1>
        </div>
    </div>
    
    <div class="row">
		<div >
			<ul class="breadcrumb">
			    <li><?php echo $this->href(array('controller' => 'usuario', 'action' => 'board', 'module' => 'default', 'content' => 'Meu Ambiente', 'checkAcl' => true))?></li> <span class="text-info divider"> >> </span>
			    <li class="active">Vincular Conta com Facebook</li>
			 </ul>
		 </div>
	</div>   
	<div class="row">
		<div style="text-align: center;">
			<fb:login-button scope="public_profile,email" auth_type="rerequest" size="xlarge" onlogin="checkLoginState();"></fb:login-button>
		</div>
	</div>
	<div id="status"></div>
</div>	




